﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;

public partial class Manage_bid_project_product_bidTable_Add : System.Web.UI.Page
{
    public string Id;
    protected void Page_Load(object sender, EventArgs e)
    {
        string BidTableId,strSql;
        labProjectId.Visible = false;
        labId.Visible = false;
        
        Id = Request.QueryString["Id"];
        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAttorney);
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumCheckProjectComp);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {

            if ( Id == null)
            {
                Response.Write("<script language=JavaScript>window.alert('没有找到相关的项目！！！！');</script>");
            }
            else
            {
                string  ProductId =SysFun.IsSQL(SysFun.ToTrim(Request.QueryString["ProductId"].ToString()));
                Db db1 = new Db();
                System.Data.IDataReader dr;
                strSql = "select productname,medicinemodel,outlookc,unit from Product where ProductId=" + ProductId;
                dr = db1.DataReader(strSql);
                while (dr.Read())
                {
                    labProductId.Text = ProductId.ToString();
                    labProductName.Text = dr["productname"].ToString();
                    labOutlookc.Text = dr["outlookc"].ToString();
                    labMedicinemodel.Text = dr["medicinemodel"].ToString();
                    labUnit.Text = dr["unit"].ToString();
                }
                dr.Close();
                dr.Dispose();
                db1.Close();

                if (Request.Form["ButDY"] == "对  应")
                {
                    BidTableId = Request.Form["rdoBidTableId"];
                    if (BidTableId != null)
                    {
                        Db db = new Db();
                        strSql = "update bid_project_product set BidTableId=" + BidTableId + " WHERE Id=" + Id + "";
                        db.Command(strSql);
                        db.Close();
                        HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
                        HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "更新", "bid_project_product", strSql, "../Agency/bid_project_product_bidTable_Add.aspx");

                        Response.Write("<script>window.opener.location.reload();window.close();</script>");
                    }
                }
                else
                {
                    
                    labId.Text = Id;
                    showGridView();
                }

            }
        }
    }
    public void showGridView()
    {
        string strConditions;
        strConditions = fctConditions();
        Db db = new Db();
        DbPage dbPage = new DbPage(db);
        dbPage.Table = "BidTable";                                               //要查询的表明
        dbPage.Key = "BidTableId";                                               //表的主键    
        dbPage.Where = strConditions;                                           //查询条件    
        dbPage.SelectField = "BidTableId,BidTableName,BidTableType,BidTableOutlookc,ProductCode";//要显示的字段
        dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);          //要显示第几页   
        dbPage.PageSize = 10;                                                    //没有显示记录条数   
        dbPage.OrderBy = "BidTableName,BidTableType,BidTableOutlookc,ProductCode";                  //排序字段
        System.Data.IDataReader dr = dbPage.ExecuteReader();
        dtlProduct.DataSource = dr;
        dtlProduct.DataBind();
        dr.Close();
        dr.Dispose();
        dbPage.Db.Close();
        db.Close();
        this.DbPageFlip1.DbPage = dbPage;//将数据传给控键

    }
    /// <summary>
    /// 生成查询条件
    /// </summary>
    /// <returns></returns>
    public string fctConditions()
    {
        string strtemp,  BidTableName, BidTableType, BidTableOutlookc, ProductCode;
        
        BidTableName = txtBidTableName.Text.ToString().Trim(); 
        BidTableOutlookc = txtBidTableOutlookc.Text.ToString().Trim();
        BidTableType = txtBidTableType.Text.ToString().Trim();
        ProductCode = txtProductCode.Text.ToString().Trim();
        strtemp = "";
        if (BidTableName != "")
        {
            strtemp = strtemp + " BidTableName like '%" + BidTableName + "%' and";
        }
        if (BidTableType != "")
        {
            strtemp = strtemp + " BidTableType like '%" + BidTableType + "%' and";
        }
        if (BidTableOutlookc != "")
        {
            strtemp = strtemp + " BidTableOutlookc like '%" + BidTableOutlookc + "%' and";
        }
        if (ProductCode != "")
        {
            strtemp = strtemp + " ProductCode like '%" + ProductCode + "%' and";
        }
        if (strtemp != "")
        {
            strtemp = "  " + strtemp.Substring(0, strtemp.Length - 3);
        }
        return strtemp;

    }
}
